<template>
  <a-modal :title="title" :width="width" :visible="visible" @ok="handleOk" :okButtonProps="{ class: { 'jee-hidden': disableSubmit } }" @cancel="handleCancel" cancelText="关闭">
    <a-spin :spinning="confirmLoading">
      <a-form ref="formRef" class="antd-modal-form" :labelCol="labelCol" :wrapperCol="wrapperCol">
        <a-row>
          <a-col :span="24">
            <a-form-item label="检查人名称" v-bind="validateInfos.examiner">
              <j-select-user v-model:value="formData.examiner"/>
            </a-form-item>
          </a-col>
        </a-row>
      </a-form>
    </a-spin>
  </a-modal>
</template>

<script lang="ts" setup>
  import { ref, nextTick, defineExpose,reactive } from 'vue';
  import TbBaseCheckScoreForm from './TbBaseCheckScoreForm.vue'
  import JSelectUser from '/@/components/Form/src/jeecg/components/JSelectUser.vue';
  import { batchEditExaminer } from '../TbBaseCheckRecord.api';
  import { Form } from 'ant-design-vue';
  
  const title = ref<string>('');
  const width = ref<number>(1200);
  const visible = ref<boolean>(false);
  const disableSubmit = ref<boolean>(false);
  const registerForm = ref();
  const emit = defineEmits(['register', 'success']);
  
  const formData = reactive<Record<string, any>>({
        ids: [],
        examiner: ''
  });
  //表单验证
  const validatorRules = {
  };
  const useForm = Form.useForm;
  const { resetFields, validateInfos } = useForm(formData, validatorRules, { immediate: true });
  const labelCol = ref<any>({ xs: { span: 24 }, sm: { span: 5 } });
  const wrapperCol = ref<any>({ xs: { span: 24 }, sm: { span: 16 } });
  const confirmLoading = ref<boolean>(false);
  /**
   * 编辑
   * @param selectedRowKeys
   */
  function edit(selectedRowKeys) {
    title.value = "配置检查人";
    visible.value = true;
    /* 选中的检查项id*/
    formData.ids = selectedRowKeys;
  }
  
  /**
   * 确定按钮点击事件
   */
  function handleOk() {
    //registerForm.value.submitForm();
    batchEditExaminer({ids: formData.ids,username: formData.examiner}, submitCallback);
  }

  /**
   * form保存回调事件
   */
  function submitCallback() {
    handleCancel();
    emit('success');
  }

  /**
   * 取消按钮回调事件
   */
  function handleCancel() {
    visible.value = false;
  }

  defineExpose({
    edit,
    disableSubmit,
  });
</script>

<style>
  /**隐藏样式-modal确定按钮 */
  .jee-hidden {
    display: none !important;
  }
</style>
